from app import Interface_mysql
class index():
    def __init__(self, page=0,number=4):
        self.page = page
        self.number =number
    # 展示信息
    def Display_information(self):
        user = Interface_mysql.Work_station(Type=1).All()
        mm =[]
        for i in user:
            pp = {"id": i.id, "name": i.name,"singer": i.singer,"Lyrics": i.Lyrics,
                  "Composer": i.Composer, "Arranger": i.Arranger,
                  "Mix": i.Mix,"Lyric_ci": i.Lyric_ci,
                  "Original_song": i.Original_song,"Type": i.Type,
                  "Address": i.Address,"date_joined": i.date_joined,
                  "last_login": i.last_login}
            mm.append(pp)
        a = mm
        print(a)
        c = []
        while a:
            b = a[:self.number]
            del a[:self.number]
            c.append(b)
        d = []
        for i in range(1, len(c) + 1):
            d.append(i)
        if self.page > len(d):
            return False
        else:
            if self.page == 0:
                bb = {'list': c, 'page': d, 'page_len': self.page}
            else:
                bb = {'list': c, 'page': d, 'page_len': self.page - 1}
            return bb
    # 轮播图
    def Carousel_figure(self, users):
        mm = []
        ab = []
        ad = []
        for i in users:
            if i.Route != "images/index_long_page.jpg":
                pp = {'id': i.id, 'name': i.name, 'Route': str(i.Route)}
                mm.append(pp)
        if mm == []:
            mm = [{'id': '0', 'name': 'None', 'Route': "images/index_long_page.jpg"}]
        ab.append(mm)
        for i in range(0, len(ab[0])):
            ad.append(i)
        cap = {'list': ab, 'page': ad, 'page_len': 0}
        return cap